﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AJWPFAdmin.Services.EF
{
    public partial class DbService
    {
        public static DbService GetDbContext(AJConfigService cfgSvc)
        {
            var builder = new DbContextOptionsBuilder<DbService>();
            var version = new MySqlServerVersion(ServerVersion.Parse("8.0.34-mysql"));
            builder.UseMySql(cfgSvc.Config.GetConnectionString("MYSQL"), version,
                bd =>
                {
                    bd.EnableRetryOnFailure(3);
                }).EnableDetailedErrors();
                //.LogTo(log => Debug.WriteLine(log),
                // new[] {
                //         DbLoggerCategory.Database.Command.Name,
                //         DbLoggerCategory.Update.Name,
                //         DbLoggerCategory.Query.Name
                // });
            return new DbService(builder.Options);
        }
    }
}
